<template>
  <div class>
    <headers></headers>

    <div class="banner">
      <p>产品介绍</p>
      <p>相比其他浏览器，我们简化了浏览处理功能，搭配内置广告拦截功能，实现更快速的网页加载体验。</p>
    </div>

    <div class="title">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>
          <a href="/">商品展示</a>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <a href="/">{{ this.name }}</a>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="list">
      <div class="li1">
        <p>产品分类</p>
        <ul :class="[id == -1 ? 'vv' : '']">
          <li
            v-for="(item, index) in list"
            @click="aa(index, item.id)"
            :class="[index == id ? 'ac' : '']"
            :key="index"
          >
            {{
              item.name
            }}
          </li>
        </ul>
      </div>
      <div class="li2">
        <p>{{ this.name }}</p>
        <div class="box">
          <div class="box1" v-for="(item, index) in par" :key="index">
            <img :src="item.pic" alt />
            <p>{{ item.name }}</p>
            <button @click="go(item.id)">查看详情</button>
          </div>

          <div v-show="par == ''">
            <h1>抱歉</h1>
            <h5>暂没有，您可以</h5>
            <button class="ck" @click="ck">查看全部</button>
          </div>
          <div class="fy" v-show="par != ''">
            <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit"></el-pagination>
          </div>
        </div>
      </div>
    </div>
     <div class='foot'>
     <div>
         <p>© 2021 GiiBee</p>
         <p>郑州市高新区高新万科广场</p>
     </div>
     </div>
       
    
  </div>
</template>

<script>
import headers from '../components/header'
import { product, produc, addproducts } from '../api/about'
import { products } from '../api/swiper'
export default {
  data() {
    return {
      list: [],
      par: [],
      id: '',
      name: '',
      page: 1,
      limit: 7,
      total: 0,
      searval: '',

    };
  },
  watch: {
    $route: {
      deep: true,
      immediate: true,
      handler(newVal) {
        console.log(newVal);
        this.searval = newVal.query.val
        addproducts({ page: this.page, limit: this.limit, keyword: this.searval }).then(res => {
          console.log(res);
          this.total = res.data.total
          this.par = res.data.data
          this.par.forEach((item) => {
            item.pic = item.pic.replace("public/", "http://websong.wang:3000/");
          });
        })
      },
    },
  },

  mounted() {
    console.log(this.searval);
    // console.log(this.$route.query.val);
    if (this.searval) {
      this.name = '全部'
      this.id = -1
      product().then(res => {
        // console.log(res);
        this.list = res.data.data
      })
      addproducts({ page: this.page, limit: this.limit, keyword: this.searval }).then(res => {
        console.log(res);
        this.total = res.data.total
        this.par = res.data.data
        this.par.forEach((item) => {
          item.pic = item.pic.replace("public/", "http://websong.wang:3000/");
        });
      })
    } else {
      this.name = '全部'
      this.id = -1
      product().then(res => {
        // console.log(res);
        this.list = res.data.data
      })
      products().then(res => {
        console.log(res);
        this.par = res.data.data
        this.par.forEach((item) => {
          item.pic = item.pic.replace("public/", "http://websong.wang:3000/");
        });
      })
    }



  },
  methods: {
    ck() {
      products().then(res => {
        // console.log(res);
        this.par = res.data.data
        this.par.forEach((item) => {
          item.pic = item.pic.replace("public/", "http://websong.wang:3000/");
        });
      })
      this.id = -1
      this.name = '全部'
    },
    aa(a, b) {
      this.id = a
      produc(b).then(res => {
        // console.log(res);
        this.name = res.data.name
      })
      addproducts({ page: this.page, limit: this.limit, category: b }).then(res => {
        // console.log(res);
        this.par = res.data.data
        this.par.forEach((item) => {
          item.pic = item.pic.replace("public/", "http://websong.wang:3000/");
        });
      })
      console.log(this.par);

    },
    go(e) {
      // console.log(e);
      this.$router.push({
        path: '/detail',
        query: {
          id: e
          // url的参数, 类似get请求的传参

        },
      })

    },
  },
  components: {
    headers
  }
};
</script>

<style lang='scss' scoped>
.foot{
    width: 100%;
    height: 80px;
    border: 1px solid #ccc;
    margin-top: 20px;
    div{
     text-align: center;
     p{
         margin-top: 10px;
     }
    }
}
.fy {
  width: 100%;
}
.vv {
  background-color: #17a2b6;
  color: white;
}
.ck {
  padding: 10px;
  background-color: #17a2b6;
  color: white;
  border: none;
  border-radius: 5px;
  margin-top: 20px;
}
.ac {
  // width: 100%;
  height: 100%;
  color: white;
  background-color: #17a2b6;
}
.box {
  // height: 800px;
  overflow: hidden;
  border-radius: 30px;
  // margin-top: 30px;
  background-color: white;
  width: 100%;
  margin: 30px auto;
  display: flex;
  padding: 10px;
  flex-wrap: wrap;
  .box1 {
    // height: 80px;
    margin: 10px;
    // background-color: #17a2b6;
    width: 45%;
    img {
      width: 100%;
    }
    p {
      padding: 10px;
    }
    button {
      // padding-left: 10px;
      margin-left: 10px;
      padding: 5px;
      color: white;
      font-size: 10px;
      background-color: #17a2b6;
      border-radius: 5px;
      border: none;
    }
  }
}
* {
  margin: 0;
  padding: 0;
}
.banner {
  text-align: center;
  width: 80%;
  border-radius: 10px;
  height: 400px;
  margin: 20px auto;
  background-image: url(../assets/img/0b02b5d4cacc55c3c5a07095b1fc79621634348848700.jpg);
  background-size: 100%;
  background-repeat: no-repeat;
  vertical-align: middle;

  p:nth-child(1) {
    padding-top: 100px;
    text-shadow: 3px 3px 3px #423f3f;
    font-size: 40px;
    color: white;
  }
  p:nth-child(2) {
    text-shadow: 3px 3px 3px #423f3f;

    font-size: 25px;
    color: white;
  }
}
.title {
  width: 80%;
  padding: 20px 5px;
  background-color: #e9ecef;
  border-radius: 10px;
  margin: auto;
}
.list {
  width: 80%;
  margin: 20px auto;
  display: flex;

  .li1 {
    // background-color: #17a2b6;
    font-size: 20px;
    color: #42494f;
    border-radius: 5px;
    width: 25%;
    overflow: hidden;
    height: 610px;
    // background-color: #423f3f;
    border: 1px solid #ccc;
    p {
      border-bottom: 1px solid #ccc;
      padding: 15px;
      background-color: #f7f7f7;
    }
    ul {
      overflow: hidden;
      list-style: none;
      width: 85%;
      border-radius: 8px;
      margin: 10px auto;
      border: 1px solid #ccc;
      li {
        padding: 10px;
        border-bottom: 1px solid #ccc;
      }
    }
  }
  .li2 {
    font-size: 20px;
    padding: 20px;
    width: 70%;
    // height: 50px;
    // background-color: rgb(68, 61, 52);
    border: 2px solid #ccc;
    border-radius: 5px;
    margin-left: 60px;
  }
}
</style>
